package com.lagou.edu.utils;

import com.lagou.edu.annotations.CustAutowired;
import com.lagou.edu.annotations.CustService;
import java.sql.SQLException;

/**
 * @ClassName TransactionManager
 * @Description 事务管理类：负责手动的开启，提交，回归
 * @Author xsl
 * @Date 2020/6/15 11:58
 * @Version 1.0
 */
@CustService
public class TransactionManager {

  @CustAutowired
  private ConnectionUtils connectionUtils;

  public void beginTransaction() throws SQLException {
    connectionUtils.getCurrentThreadConn().setAutoCommit(false);
  }

  public void commit() throws  SQLException{
    connectionUtils.getCurrentThreadConn().commit();
  }

  public void rollback() throws  SQLException{
    connectionUtils.getCurrentThreadConn().rollback();
  }
}
